<?php

namespace app\admin\controller;

use think\Db;
use think\Request;


class Centent extends Admin
{
    // 查询数据
    public function index(Request $request)
    {
        $res = $request->get();
        if (!empty($res['title'])) {
            $data = $res['title'];
            $where['name'] = ['like', '%'.$data.'%'];
            $count = Db::table('hmy_user')->where($where)->paginate(4)->count();
            if ($count == 0) {
                 $this->success('未找到查询的内容');
            }
        }else{
            $where = "";
        }

        $data = Db::table('hmy_user')->field(true)->where($where)->paginate(4);
        // //查询首分类
        // //获取分页显示

        $page = $data->render();
        $this->assign('page', $page);
        $this->assign('data', $data);

        return $this->fetch('centent/centent');

    }    


    // 查询数据
    public function disbale(Request $request)
    {
        $res = $request->get();
        if (!empty($res['title'])) {
            $data = $res['title'];
            $where['name'] = ['like', '%'.$data.'%'];
            $count = Db::table('hmy_user')->where($where)->paginate(4)->count();
            if ($count == 0) {
                 $this->success('未找到查询的内容');
            }
        }else{
            $where = "";
        }

        $data = Db::table('hmy_user')->field(true)->where($where)->paginate(4);
        // //查询首分类
        // //获取分页显示

        $page = $data->render();
        $this->assign('page', $page);
        $this->assign('data', $data);

        return $this->fetch('centent/disable');

    }


    // 查询数据
    // public function find(Request $search, $page=null,$id)
    // {
    //     // 接受数据
    //     $ll = $search->get();

    //     if (empty($ll)) {
    //         $ll['title'] = '';
    //     }

    //     $title = $ll['title'];

    //     if (empty($ll)) {

    //         $res = Db::name('picture')->where('user_id ='.$id)->select();
    //         $num = ceil(count($res) / 3);
    //         $sql = Db::name('picture')->where('user_id ='.$id)->field(['pass'],true)->paginate(3);

    //     }else{

    //         $res = Db::name('picture')->where('user_id ='.$id)->where('title','like','%'.$title.'%')->select();
    //         $num = ceil(count($res) / 3);
    //         $sql = Db::name('picture')->where('user_id ='.$id)->where('title','like','%'.$title.'%')->field(['pass'],true)->paginate(3);
            
    //     }

    //     return view('admin@centent/detail',['list'=>$sql,'num' => $num, 'page' => $page,'id' => $id]);
    // }

 

    // 查询数据
    public function find($id)
    {



        $data = Db::table(['hmy_user'=>'u','picture' => 'p'])
                    ->where('p.user_id = u.id && u.id = '.$id)
                    ->select();
        // var_dump($data);

        return view('admin@centent/detail',['data'=>$data]);
    }


    public function role($id)
    {
        $id = input('id');
        var_dump($id);die;
         Db::table('picture')->where('id ='.$id) ->delete();

        return view('admin@centent/index');
    }


}


